package demo.hello;

import org.apache.rocketmq.client.QueryResult;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class ProducerMany {
    public static void main(String[] args) throws MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
        String nameSrvAddr="localhost:9876";
        producer.setNamesrvAddr(nameSrvAddr);
        producer.start();

        for (int i = 0; i < 1; i++)
            try {
                {
                    Message msg = new Message("TopicTest1",
                        "TagA",
                        "key113",
                        ("Hello world"+i).getBytes(RemotingHelper.DEFAULT_CHARSET));
                    SendResult sendResult = producer.send(msg);
                    System.out.printf("%s%n", sendResult);

//                    QueryResult queryMessage =
//                        producer.queryMessage("TopicTest1", "key113", 10000, 0, System.currentTimeMillis());
//                    for (MessageExt m : queryMessage.getMessageList()) {
//                        System.out.printf("%s%n", m);
//                        System.out.println(new String(m.getBody()));
//                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        producer.shutdown();
        
    }
}
